<?php
/**
 * Created by PhpStorm.
 * User: Kevin
 * Date: 2018/12/19
 * Time: 10:11
 */
namespace app\admin\controller;
use think\Db;
class System extends Base
{
    /*
     * 关于我们
     */
    public function  about(){
        if(request()->isAjax ()){
            extract(input());
            $Nowpage = input('page') ? input('page'):1;
            $limits = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::name('about')
                ->where(['a_id'=>1])
                ->count();
            $lists = Db::name('about')
                ->where(['a_id'=>1])
                ->field(['a_id','a_logo','a_content','a_law','a_agree','a_phone','a_email','a_address','a_name','a_update_time'])
                ->page($Nowpage,$limits)
                ->select ();
            return json(['code'=>220,'msg'=>'','count'=>$count,'data'=>$lists]);
        }
        return $this->fetch('system/about');
    }

    /*
     * 编辑关于我们
     */
    public function aboutEdit(){
        if(request()->isPost ()){
            extract(input());
            $param = [
                'a_logo'=>$logo,
                'a_content'=>$content,
                'a_law'=>$law,
                'a_agree'=>$agree,
                'a_phone'=>$phone,
                'a_email'=>$email,
                'a_address'=>$address,
                'a_name'=>$name,
                'a_update_time'=>date('Y-m-d H:i:s')
            ];
            $res = Db::name('about')
                ->where('a_id',$id)
                ->update($param);
            if($res){
                return json(['code'=>200,'msg'=>'编辑成功']);
            }else{
                return json(['code'=>100,'msg'=>'编辑失败']);
            }
        }
        $info = Db::name('about')
            ->where(['a_id'=>input('id')])
            ->field('a_id,a_logo,a_content,a_law,a_agree,a_phone,a_email,a_address,a_name')
            ->find();
        return $this->fetch('system/about_edit',['info'=>$info]);
    }

    /*
     * 意见反馈
     */
    public function suggest(){
        if(request()->isAjax ()){
            extract(input());
            $map = [];
            if(isset($key)&&$key!="")
            {
                $map['user_username|s_content'] = ['like',"%" . $key . "%"];
            }
            if(isset($start)&&$start!=""&&isset($end)&&$end=="")
            {
                $map['s_time'] = ['>= time',$start];
            }
            if(isset($end)&&$end!=""&&isset($start)&&$start=="")
            {
                $map['s_time'] = ['<= time',$end];
            }
            if(isset($start)&&$start!=""&&isset($end)&&$end!="")
            {
                $map['s_time'] = ['between time',[$start,$end]];
            }
            $Nowpage = input('page') ? input('page'):1;
            $limits = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::name('suggest s')
                ->join('u_user u','s.s_user_id = u.user_id','left')
                ->where($map)
                ->count();
            $lists = Db::name('suggest s')
                ->join('u_user u','s.s_user_id = u.user_id','left')
                ->where($map)
                ->field('s_id,s_content,s_time,user_username')
                ->order('s_time DESC')
                ->page($Nowpage,$limits)
                ->select ();
            return json(['code'=>220,'msg'=>'','count'=>$count,'data'=>$lists]);
        }
        return $this->fetch ('system/suggest');
    }
}